! function(e, $, mui) {

    "use strict";
    var config = {};
    // 定义页面
    var p = function(config) {
        var t = this;
        t.config = config;
        t.userInfo = null;
        t.page = {
            page: 0,
            perpage: 0,
            more: true
        };
        t.element = {
            listContainer: $('#list-container .list'),
            emptyContainer: $('#list-container .empty-list'),
            button_check:$('.button_check'),
            sdate: $('.sdate'),
            ddate: $('.ddate')
        };

        // 初始化
        t.init();

        // 事件监听
        t.listen(11);
    };

    var pt = p.prototype;

    // 页面初始化
    pt.init = function() {
        var t = this;
        t.userInit();
        // 列表加载
            
        var myDate = new Date((new Date()).getTime() - 86400 * 365 * 1000);
        
        t.element.sdate.val((myDate).Format('yyyy-MM-dd'));
        t.element.ddate.val((new Date()).Format('yyyy-MM-dd'));
          t.listInit();
    };

    // 事件初始化
    pt.listen = function(param) {
        var t = this;
        // 刷新列表
        t.element.emptyContainer.on('tap', function() {
            t.listInit();
        });
        
        // 点击查询
        t.element.button_check.on('tap', function() {
            t.listInit();
        });

		// 时间
    	var dtPicker = new mui.DtPicker({type:"date"});	
    	
    	// 选择开始时间
		t.element.sdate.parent().on('tap', function () {
		    dtPicker.show(function (item) {
			    t.element.sdate.val(item.value);
		    });
		});
		
    	// 选择截止时间
		t.element.ddate.parent().on('tap', function () {
		    dtPicker.show(function (item) {
			    t.element.ddate.val(item.value);
		    });
		});
    };

    // 列表初始化
    pt.listInit = function() {
        var t = this;
        t.element.listContainer.html('');
        t.page = {
            page: 0,
            perpage: 5,
            more: true
        };

        // 列表加载
        t.listLoad();
    };

    // 列表加载
    pt.listLoad = function() {
        var t = this;
        t.page.page++;

        if(t.page.more ===false) {
//          mui('#list-container').pullRefresh().endPulldownToRefresh();
            return;
        }
        
        var input_check = $('.input_check').val();
        var sdate = t.element.sdate.val();
        var ddate = t.element.ddate.val();
        
        if(!sdate) {
        	mui.toast('请选择开始时间');
        	return;
        }
        if(!ddate) {
        	mui.toast('请选择截止时间');
        	return;
        }
            
        crossDomainAjax({
            url: apiUrl,
            pastDate: {
                "op": "Phone_GetWQ_Store",
                "Code": input_check,
                "Pid": userInfo.Pid,
                "sdate": sdate,
                "ddate": ddate
            },
            nativeFlg: false,
            requestType: 'POST'
        }, function(result) {
            if(result.status == 0) {
                mui.toast(result.Message);
                return;
            }
            console.log(userInfo.Pid);
            console.log(result);
            var i = 0;
            var order =0;
            result.Main.forEach(function(item) {
                    i++
                    order++
                    var mystime = new Date(item.R_Datetime).toLocaleDateString();
                    var html = '<tr class="open-url" data-url="transfer_detail.html?code='+item.CKCode+'">';
                   // html += '<td>' + item.CKCode + '</td>';
                    html += '<td>' + order + '</td>';
                    html += '<td>' + item.TiDanCode + '</td>';
                    html += '<td>' + item.WQUnit + '</td>';
                    html += '<td>' + item.NewWQUnit + '</td>';
                    html += '<td>' + item.UnitName+ '</td>';
                    html += '<td>' + item.StoreName + '</td>';                 
                    html += '<td>' + item.FirstCount + '</td>';
                    html += '<td>' + item.Weight + '</td>';
                    html += '<td>' + item.MaoWeight + '</td>';
                    html += '<td>' + item.Volume + '</td>';
                    html += '<td>' + item.C_Code + '</td>';
                    html += '<td>' + item.R_Code + '</td>';
                    html += '<td>' + mystime + '</td>';
                    //html += '<td>' + item.SecondCount + '</td>';
                    //html += '<td>' + item.UnitName + '</td>';
                    //html += '<td>' + item.NewUnitName + '</td>';
                    html += '</tr>';
                    t.element.listContainer.append(html);
            });
            console.log(JSON.stringify(result));
            
           
            // 判断列表是否为空
            if(t.page.page == 1) {
                if(i > 0) {
                    t.element.listContainer.show();
                    t.element.emptyContainer.hide();
                } else {
                	mui.toast('暂无数据');
                    t.element.listContainer.hide();
                    t.element.emptyContainer.show();
                }
            }

//          mui('#list-container').pullRefresh().endPulldownToRefresh();
        });
    };

    // 用户信息初始化
    pt.userInit = function() {
        var t = this;
        t.userInfo = getLocalUserInfo();
    };

    e.page = new p(config);
   /* mui.init({
      pullRefresh: {
          container: '#list-container',
          down: {
              style: 'circle',
              callback: function() {
                  e.page.listInit();
             } // 下拉刷新
          }
      }
    });*/

  e.page.listInit();

}(window, $, mui);